<%--
  Created by IntelliJ IDEA.
  User: t430
  Date: 2018/7/31
  Time: 9:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<html>
<head>
    <head>
        <meta charset="UTF-8">
        <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/css/common.css">
        <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/css/main.css">
        <script type="text/javascript" src="${pageContext.request.contextPath}/statics/js/jquery.min.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/statics/js/colResizable-1.3.min.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/statics/js/common.js"></script>

        <script type="text/javascript">
            $(function(){
                $(".list_table").colResizable({
                    liveDrag:true,
                    gripInnerHtml:"<div class='grip'></div>",
                    draggingClass:"dragging",
                    minWidth:30
                });

            });
        </script>
        <title>Document</title>

        <script type="text/javascript">
            function deleteNewsType(id){
                if(!confirm("数据一旦删除无法恢复，请问您确定要删除吗?")){
                    return;
                }

                $.get("${pageContext.request.contextPath}/newstype/delete",{id:id,r:Math.random()},function(data){
                    if($.trim(data) =="1"){
                        alert("删除数据成功!");

                    }else if($.trim(data) =="-1"){
                        alert("删除数据失败!必须删除所有对应类别的子类别才能删除该类别！");
                    }
                    else{
                        alert("删除数据失败!");
                    }
                    window.location=window.location;

                });

            }
            function selectAll(){

                var cbAll=document.getElementsByName("cbAll")[0];
                var cbItem=document.getElementsByName("cbItem");
                for(var i=0;i<cbItem.length;i++){
                    cbItem[i].checked=cbAll.checked;
                }
            }

            function deleteAllSelNewsType(){
                if(confirm("数据一旦删除无法恢复，请问您确定要删除吗？")){
                    var ids="";//最终要删除数据的 所有的id
                    var cbItem=document.getElementsByName("cbItem");
                    for(var i=0;i<cbItem.length;i++){
                        if(cbItem[i].checked){
                            ids+=cbItem[i].value+",";
                        }
                    }
                    if(ids==""){
                        alert("请选择要删除的选项！");
                        return;
                    }
                    //ids=ids.substr(ids,ids.length-1);
                    ids+="-1";

                    $.get("${pageContext.request.contextPath}/newstype/deleteall",{ids:ids,r:Math.random()},function(data){
                        if(parseInt($.trim(data)) >0){
                            alert("批量删除成功!");
                        }else if($.trim(data)=="-1"){
                            alert("批量删除失败!当前类别含有子类别，无法删除！");
                        }else{
                            alert("批量删除失败!");
                        }

                        window.location=window.location;




                    });
                }
            }




        </script>






    </head>
<body>
<div class="container">

    <div id="search_bar" class="mt10">
        <form method="get" action="${pageContext.request.contextPath}/newstype/list">
        <div class="box">
            <div class="box_border">
                <div class="box_top"><b class="pl15">搜索</b></div>
                <div class="box_center pt10 pb10">
                    <table class="form_table" border="0" cellpadding="0" cellspacing="0">
                        <tr>
                            <td>类别名称</td>
                            <td><input type="text" value="${newsType.typeName}" name="typeName" class="input-text lh25" size="10"></td>
                            <td>父类别</td>
                            <td>
                    <span class="fl">
                      <div class="select_border">
                        <div class="select_containers ">
                            <select name="parentId" class="select">
            <option value="0">==所有类别==</option>
            <c:forEach var="item" items="${plist}">
                <option ${newsType.parentId==item.id?"selected":""} value="${item.id}">${item.typeName}</option>


            </c:forEach>
        </select>

                        </div>
                      </div>
                    </span>
                            </td>
                        </tr>

                    </table>
                </div>
                <div class="box_bottom pb5 pt5 pr10" style="border-top:1px solid #dadada;">
                    <div class="search_bar_btn" style="text-align:right;">
                        <input type="submit" value="搜索" class="ext_btn ext_btn_submit">
                        <%--<input type="button" value="返回" onclick="location.href='javascript:history.go(-1)'" class="ext_btn">--%>
                        <%--<input type="button" class="ext_btn ext_btn_success" value="成功">--%>
                        <input type="button"  onclick="deleteAllSelNewsType();" class="ext_btn ext_btn_error" value="批量删除">
                        <a href="${pageContext.request.contextPath}/newstype/add" class="ext_btn"><span
                                class="add"></span>添加</a>
                    </div>
                </div>
            </div>
        </div>
        </form>
    </div>


    <div id="table" class="mt10">
        <div class="box span10 oh">
            <table width="100%" border="0" cellpadding="0" cellspacing="0" class="list_table">
                <tr>
                    <th width="30"><input type="checkbox" onclick="selectAll();" name="cbAll" /></th>
                    <th width="100">ID</th>
                    <th width="100">类别名称</th>
                    <th>父类别</th>
                    <th>创建日期</th>
                    <th>操作</th>
                </tr>
               <c:forEach var="item" items="${list}">
                   <tr class="tr">
                       <td class="td_center"><input type="checkbox" value="${item.id}" name="cbItem" /></td>
                       <td>${item.id}</td>
                       <td>${item.typeName}</td>
                       <td>${item.parentName}</td>
                       <td> <fmt:formatDate value="${item.createDate}" pattern="yyyy-MM-dd"></fmt:formatDate> </td>
                       <td><a href="${pageContext.request.contextPath}/newstype/update?id=${item.id}">修改
                       </a>&nbsp;
                           <a href="javascript:void(0)" onclick="deleteNewsType(${item.id});">删除</a></td>

                   </tr>

               </c:forEach>




            </table>
            <div class="page mt10">
                <div class="pagination">
                    <ul>

                        <li class="first-child"><a href="${pageContext.request.contextPath}/newstype/list?currPageNo=1&parentId=${newsType.parentId}&typeName
=${newsType.typeName}">首页</a></li>
                        <li><a href="${pageContext.request.contextPath}/newstype/list?currPageNo=${pageTool.currPageNo-1}&parentId
=${newsType.parentId}&typeName
=${newsType.typeName}">上一页</a></li>
                        <c:forEach var="preNum" items="${prePages}">
                            <li><a href="${pageContext.request.contextPath}/newstype/list?currPageNo=${preNum}&parentId
=${newsType.parentId}&typeName
=${newsType.typeName}">${preNum}</a></li>

                        </c:forEach>

                        <li class="active"><span>${pageTool.currPageNo}</span></li>
                        <c:forEach var="nextNum" items="${nextPages}">
                            <li><a href="${pageContext.request.contextPath}/newstype/list?currPageNo=${nextNum}&parentId
=${newsType.parentId}&typeName
=${newsType.typeName}">${nextNum}</a></li>

                        </c:forEach>
                        <li><a href="${pageContext.request.contextPath}/newstype/list?currPageNo=${pageTool.currPageNo+1}&parentId
=${newsType.parentId}&typeName
=${newsType.typeName}">下一页</a></li>
                        <li class="last-child"><a href="${pageContext.request.contextPath}/newstype/list?currPageNo=${pageTool.pageCount}&parentId
=${newsType.parentId}&typeName
=${newsType.typeName}">末页</a></li>
                    </ul>
                </div>

            </div>
        </div>
    </div>


</div>
</body>
</html>
